package site.suremotoo.springbootblog.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import site.suremotoo.springbootblog.dao.ArticleDao;
import site.suremotoo.springbootblog.pojo.Article;
import site.suremotoo.springbootblog.service.ArticleService;

/**
 * @author liulx
 * @description TODO
 * @date 2020-08-30 19:32
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    ArticleDao articleDao;

    /**
     * 分页查询
     *
     * @param page     页码
     * @param pageSize 每页显示数量
     * @return 分页结果
     */
    @Override
    public Page<Article> listArticlesByPage(int page, int pageSize) {
        Pageable pageable = PageRequest.of(page, pageSize);
        return articleDao.findAll(pageable);
    }

}
